package com.dawnling.mvvmdemo.demo2;

import android.content.Context;
import android.view.View;
import android.widget.Toast;

import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;
import androidx.databinding.library.baseAdapters.BR;

public class MvvmModule extends BaseObservable {
    private Context context;
    private String name;
    private String result;
    private String inputName;

    public MvvmModule(Context context, String name) {
        this.context = context;
        this.name = name;
    }

    public void getData(View v) {
        if (inputName == null) {
            Toast.makeText(context, "不可为空", Toast.LENGTH_SHORT).show();
            return;
        }
        if (inputName.equals(getName())) setResult(getInputName() + "验证成功！");
        else setResult("验证失败！");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Bindable
    public String getInputName() {
        return inputName;
    }

    @Bindable
    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
        notifyPropertyChanged(BR.result);
    }

    public void setInputName(String inputName) {
        this.inputName = inputName;
        notifyPropertyChanged(BR.inputName);
    }
}
